package com.contory.ssn_lgnd.app.maingame;

import android.util.Log;

import com.contory.ssn_lgnd.app.comp.DrawPtr;
import com.contory.ssn_lgnd.app.comp.UpdatePtr;
import com.contory.ssn_lgnd.app.comp.ViewObject;
import com.contory.ssn_lgnd.framework.gl.Animation;
import com.contory.ssn_lgnd.framework.gl.SpriteBatcher;
import com.contory.ssn_lgnd.framework.gl.TextureRegion;
import com.contory.ssn_lgnd.framework.math.Vector2;

public class TextureEffectAnimation implements UpdatePtr, DrawPtr{
	Animation ani;
	float stateTime = 0;
	TextureRegion tr;
	int mode;
	boolean aniEndBool = false;
	float a = 1;
	ViewObject view;
	//Vector2 pos = new Vector2();
	
	byte state = 0;
	
	public TextureEffectAnimation(){
		view = new ViewObject();
	}
	
	public void setInit(Animation ani, int mode, float x, float y, float w, float h){
		this.ani = ani;
		this.mode = mode;
		tr = ani.getKeyFrame(0, mode);
		state = 0;
		a = 1;
		aniEndBool = false;
		stateTime = 0.0f;
		view.setXY(x, y);
		view.setWH(w, h);
		//pos.set(x, y);
	}

	@Override
	public void update(float deltaTime) {
		if(aniEndBool)
			return;
		switch(state){
			case 0:
				stateTime += deltaTime;
				tr = ani.getKeyFrame(stateTime, mode);
				if(ani.getAniEndBool()){
					stateTime = 0.0f;
					state = 1;
				}
			break;
			
			case 1:
				a -= deltaTime * 2;
				if(a < 0){
					a = 0;
					state = 2;
					aniEndBool = true;
				}
			break;
			
			case 2:
			break;
		}
	}
	
	public float getAlpha(){
		return a;
	}
	
	public boolean getAniEndBool(){
		return aniEndBool;
	}
	
	public TextureRegion getTextrueRegion(){
		return tr;
	}

	@Override
	public void draw(SpriteBatcher batcher) {
		batcher.drawSprite(view.x, view.y, view.w, view.h, 1, 1, 1, a, tr);
	}
}
